package com.expert.config;

import com.expert.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RabbitMQConfig
 * @Author: cxs
 * @Date: 2024/03/26 18:54
 * @Description:
 **/
@Configuration
public class RabbitMQConfig {


    /**
     * 定义交换机
     */
    @Bean(RabbitMQConstant.EXCHANGE_TOPIC)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(RabbitMQConstant.EXCHANGE_TOPIC).durable(true).build();
    }

    /**
     * 定义短信队列
     */
    @Bean(RabbitMQConstant.QUEUE_SMS)
    public Queue queueSms(){
        return new Queue(RabbitMQConstant.QUEUE_SMS,true);
    }

    /**
     * 将短信队列绑定到交换机
     */
    @Bean
    public Binding bindingSms(@Qualifier(RabbitMQConstant.QUEUE_SMS) Queue smsQueue, @Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(smsQueue).to(exchange).with(RabbitMQConstant.KEY_SMS).noargs();
    }

    /**
     * 定义邮箱队列
     */
    @Bean(RabbitMQConstant.QUEUE_EMAIL)
    public Queue queueEmail(){
        return new Queue(RabbitMQConstant.QUEUE_EMAIL,true);
    }

    /**
     * 将邮箱队列和交换机绑定
     */
    @Bean
    public Binding bindingEmail(@Qualifier(RabbitMQConstant.QUEUE_EMAIL) Queue emailQueue, @Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(emailQueue).to(exchange).with(RabbitMQConstant.KEY_EMAIL).noargs();
    }

    /**
     * 定义系统通知队列
     */
    @Bean(RabbitMQConstant.QUEUE_SYS)
    public Queue queueSys(){
        return new Queue(RabbitMQConstant.QUEUE_SYS,true);
    }

    /**
     * 将系统队列和交换机绑定
     */
    @Bean
    public Binding bindingSys(@Qualifier(RabbitMQConstant.QUEUE_SYS) Queue sysQueue, @Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(sysQueue).to(exchange).with(RabbitMQConstant.KEY_SYS).noargs();
    }

    @Bean(RabbitMQConstant.KEY_CANCEL_PROJECT_EMAIL)
    public  Queue queueCancelEmail(){
        return new Queue(RabbitMQConstant.KEY_CANCEL_PROJECT_EMAIL,true);
    }
    @Bean
    public  Binding bindingCancelEmail(@Qualifier(RabbitMQConstant.KEY_CANCEL_PROJECT_EMAIL) Queue emailQueue,@Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(emailQueue).to(exchange).with(RabbitMQConstant.KEY_CANCEL_PROJECT_EMAIL).noargs();
    }
    @Bean(RabbitMQConstant.KEY_CANCEL_PROJECT_SYS)
    public  Queue queueCancelSys(){
        return new Queue(RabbitMQConstant.KEY_CANCEL_PROJECT_SYS,true);
    }
    @Bean
    public  Binding bindingCancelSys(@Qualifier(RabbitMQConstant.KEY_CANCEL_PROJECT_SYS) Queue emailQueue,@Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(emailQueue).to(exchange).with(RabbitMQConstant.KEY_CANCEL_PROJECT_SYS).noargs();
    }

    @Bean(RabbitMQConstant.KEY_RE_EXTRACT)
    public Queue queueReExtract(){
        return new Queue(RabbitMQConstant.KEY_RE_EXTRACT,true);
    }
    @Bean
    public  Binding bindingReExtract(@Qualifier(RabbitMQConstant.KEY_RE_EXTRACT) Queue queue,@Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(RabbitMQConstant.KEY_RE_EXTRACT).noargs();
    }

    @Bean(RabbitMQConstant.KEY_CANCEL_EXTRACT_RESULT)
    public Queue queueCancelExtractResult(){
        return new Queue(RabbitMQConstant.KEY_CANCEL_EXTRACT_RESULT,true);
    }
    @Bean
    public  Binding bindingCancelExtractResult(@Qualifier(RabbitMQConstant.KEY_CANCEL_EXTRACT_RESULT) Queue queue,@Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(RabbitMQConstant.KEY_CANCEL_EXTRACT_RESULT).noargs();
    }
}

